<?php

namespace app\api\controller;

use app\common\controller\Api;
use \app\admin\model\Shop;
use PhpOffice\PhpSpreadsheet\Reader\Xls\MD5;
use think\Request;

/**
 * 抖店
 */
class ShopAssistant extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 鉴权
     */
    public function checkPermission()
    {
//        $shopId = $this->request->get("shopId");
//        $shopName = $this->request->get("shopName");
        $shopId = $this->request->request("shopId");
        $shopName = $this->request->request("shopName");

        $shop = Shop::where('shop_no', $shopId)->find();

        $shopLog = new \app\admin\model\ShopCheckLog();
        $shopLog->shop_no = $shopId;
        $shopLog->shop_name = $shopName;


        if($shop){

            //放行
            $shopLog->action = 1;
            $shopLog->save();

            $time = Request::instance()->server('REQUEST_TIME');
            $this->success('success', ['permission' => MD5(MD5($shopId.$time.$shopName))]);
        }else{
            //拒绝
            $shopLog->action = 0;
            $shopLog->save();

            $time = Request::instance()->server('REQUEST_TIME');
            $this->error('插件初始化失败，请联系技术支持。');
        }



        //$this->success('success', ['permission' => '111111','shopId'=>$shopId,'shopName'=>$shopName]);
    }

}
